package com.jinxin.platform.cddjnhjcxtsysset.service.impl;

import com.jinxin.platform.base.common.pojo.JsonResult;
import com.jinxin.platform.cddjnhjcxtsysset.bean.CddjnhjcxtsyssetHomeExpend;
import com.jinxin.platform.cddjnhjcxtsysset.bean.CddjnhjcxtsyssetHomePrice;
import com.jinxin.platform.cddjnhjcxtsysset.bean.CddjnhjcxtsyssetHomeReleva;
import com.jinxin.platform.cddjnhjcxtsysset.mapper.CddjnhjcxtsyssetHomeRelevaMapper;
import com.jinxin.platform.cddjnhjcxtsysset.service.ICddjnhjcxtsyssetHomeRelevaService;
import com.jinxin.platform.cddjnhjcxtsysset.utils.IdWorker;
import com.jinxin.platform.cddjnhjcxtsysset.utils.Utils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * All rights Reserved, Designed By www.beonelot.com
 *
 * @version: V1.0
 * @Copyright: www.beonelot.com Inc. All rights reserved.
 * @Description：
 * @Date: 2021-07-20
 * @Author: Lingnan
 **/
@Service
public class CddjnhjcxtsyssetHomeRelevaServiceImpl implements ICddjnhjcxtsyssetHomeRelevaService {
    @Autowired
    private CddjnhjcxtsyssetHomeRelevaMapper homeRelevaMapper;
    @Resource
    private IdWorker idWorker;

    @Override
    public CddjnhjcxtsyssetHomeReleva selectOne(HashMap param) {
        return homeRelevaMapper.selectOne(param);
    }

    @Override
    public List<CddjnhjcxtsyssetHomeReleva> list(HashMap param) {
        return homeRelevaMapper.list(param);
    }

    @Override
    public JsonResult saveOrUpdate(CddjnhjcxtsyssetHomeReleva record) {
        if (record == null){
            return JsonResult.error("参数错误，操作失败");
        }
        List<CddjnhjcxtsyssetHomeReleva> list = new ArrayList<>();
        HashMap param = new HashMap();
        param.put("type",record.getType());
        CddjnhjcxtsyssetHomeReleva homeReleva = homeRelevaMapper.selectOne(param);
        int count;
        if(homeReleva == null){
            record.setId(String.valueOf(idWorker.nextId()));
            count = homeRelevaMapper.insert(record);
        }else {
            homeReleva.setWhether(record.getWhether());
            count = homeRelevaMapper.updateByKey(homeReleva);
        }
        if(count > 0){
            return JsonResult.ok("操作成功","");
        }else {
            return JsonResult.error("操作失败，请重试");
        }
    }
}
